package com.yvchen.yc_system.module.qrcode.service;

import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.io.IOException;

@Service
public class QRService {

    public void generateFile(String content, File file){
        //生成到本地文件
//        QrCodeUtil.generate(content, qrconig, file);
    }
    //输出到流
    public void generateStream(String content, HttpServletResponse response) throws IOException {
        QrConfig qrConfig = new QrConfig();
        qrConfig.setBackColor(Color.white.getRGB());
        qrConfig.setForeColor(Color.black.getRGB());
        qrConfig.setWidth(1000);
        qrConfig.setHeight(1000);
        QrCodeUtil.generate(content,qrConfig,"png",response.getOutputStream());
    }
}
